﻿using System;
using System.Collections.Generic;
using BLL;
using Model;
using CrystalDecisions.CrystalReports.Engine;

public partial class StatisticData_OnceandPassRate_Test_Active_OandPRbyDT_Test_Active : System.Web.UI.Page
{
    private DateTime var_starttime
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime var_stoptime
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
        this.CrystalReportSource2.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var_starttime = DateTime.Parse(this.TextBox1.Value.Trim());
        var_stoptime = DateTime.Parse(this.TextBox2.Value.Trim());
        BindOPRCR();
        BindPRCR();
    }

    private void BindOPRCR()
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/StatisticData/OnceandPassRate/OPRbyPIDDT.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
        txtTestTime.Text = var_starttime.ToString() + "-" + var_stoptime.ToString();

        IList<Time_PRInfo> list = GetOPRData();
        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }

    private IList<Time_PRInfo> GetOPRData()
    {
        IList<Time_PRInfo> oprs = new List<Time_PRInfo>();
        Test_PRT opr = new Test_PRT();
        oprs = opr.GetOPRbyPID_DT_Test_Active(var_starttime, var_stoptime);
        return oprs;
    }

    private void BindPRCR()
    {
        this.CrystalReportSource2.ReportDocument.Load(Server.MapPath("~/StatisticData/OnceandPassRate/PRbyPIDDT.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource2.ReportDocument.ReportDefinition.ReportObjects["Text1"];
        txtTestTime.Text = var_starttime.ToString() + "-" + var_stoptime.ToString();

        IList<Time_PRInfo> list = GetPRData();
        this.CrystalReportSource2.ReportDocument.SetDataSource(list);
        this.CrystalReportSource2.DataBind();
        this.CrystalReportViewer2.ReportSource = CrystalReportSource2;
        this.CrystalReportViewer2.DataBind();
        this.CrystalReportViewer2.Visible = true;
    }

    private IList<Time_PRInfo> GetPRData()
    {
        IList<Time_PRInfo> oprs = new List<Time_PRInfo>();
        Test_PRT opr = new Test_PRT();
        oprs = opr.GetPRbyPID_DT_Test_Active(var_starttime, var_stoptime);
        return oprs;
    }
}
